//
// Created by wujehy on 2020/5/31.
//


#include <iostream>
#include <iomanip>
#include "Tool/KeyValueBase.h"
using namespace GeeJoan::DataBase;
int main()
{
    std::string fileName= "test.gkv";
    KeyValueFileService serviceSave ;
    serviceSave.setMFileName(fileName);
    serviceSave.Set2<int64_t>("test1" , 123);
    serviceSave.Set2<int64_t>("test2" , 123);
    serviceSave.Set2<int64_t>("test3" , 123);
    serviceSave.Set2<int64_t>("test4" , 123);
    serviceSave.Set2<int>("test5" , 123);
    serviceSave.Set2<std::string>("test6" , "123");
    serviceSave.Set2<double>("test7" , 1.234567890123);
    serviceSave.Set2<float >("test8" , 1.234567890123);

    serviceSave.save();

    KeyValueFileService serviceLoad ;
    serviceLoad.setMFileName(fileName);
    serviceLoad.load();

    serviceLoad.ForEcho([](std::string key, KeyValueDataTypePort port){
        std::cout<<"key : "<< key<<" , value : " << port->getValue(true)<<std::endl;

        if (port->getType() == ValueType_DOUBLE)
        {
            // 特殊处理 double

            std::cout <<"double : "<< std::fixed <<std::setprecision(15)  << port->getDouble()<<std::endl;
        }

        if (port->getType() == ValueType_FLOAT)
        {
            // 特殊处理 double
            // 精度丢失
            std::cout <<"float : "<< std::fixed <<std::setprecision(15) << port->getFloat()<<std::endl;
        }
    });
    return 0;
}